document.addEventListener('DOMContentLoaded', function() {
    // Attempt to retrieve the stored data from local storage after the page has loaded
    chrome.storage.local.get(['baiyingID', 'douyinTeam', 'leaderPhone', 'aweid', 'wxRobotLink'], function(data) {
        // Check and set the value for baiyingID
        if (data.baiyingID) {
            document.getElementById('baiyingID').value = data.baiyingID;
            console.log('Buying ID loaded into input:', data.baiyingID);
        }

        // Check and set the value for aweid
        if (data.aweid) {
            document.getElementById('aweid').value = data.aweid;
            console.log('aweid loaded into input:', data.aweid);
        }

        // Check and set the value for douyinTeam
        if (data.douyinTeam) {
            document.getElementById('douyinTeam').value = data.douyinTeam;
            console.log('Team Name loaded into input:', data.douyinTeam);
        }

        // Check and set the value for leaderPhone
        if (data.leaderPhone) {
            document.getElementById('leaderPhone').value = data.leaderPhone;
            console.log('Leader Phone loaded into input:', data.leaderPhone);
        }

        // Check and set the value for leaderPhone
        if (data.leaderPhone) {
            document.getElementById('wxRobotLink').value = data.wxRobotLink;
            console.log('wxRobotLink loaded into input:', data.wxRobotLink);
        }
    });
});




document.getElementById('submitButton').addEventListener('click', function() {
    // Collect data from each input field
    var baiyingID = document.getElementById('baiyingID').value;
    var douyinTeam = document.getElementById('douyinTeam').value;
    var leaderPhone = document.getElementById('leaderPhone').value;
    var aweid = document.getElementById('aweid').value;
    var wxRobotLink = document.getElementById('wxRobotLink').value;

    // Save data to local storage
    chrome.storage.local.set({
        'baiyingID': baiyingID,
        'douyinTeam': douyinTeam,
        'leaderPhone': leaderPhone,
        'aweid': aweid,
        'wxRobotLink': wxRobotLink
    }, function() {
        console.log('User data saved:');
        console.log('Buying ID:', baiyingID);
        console.log('aweid:', aweid);
        console.log('Team Name:', douyinTeam);
        console.log('Leader Phone:', leaderPhone);
        console.log('wxRobotLink:', wxRobotLink);
    });
});



